import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router =  new Router({
  mode: 'history', //去掉 #
  routes: [
    { path: '/', redirect: 'login'},
    { path: '/login', name: 'login', meta: {title: '登录'},  component: () => import('@/view/Login.vue') },
    { 
      path: '/home', 
      meta: { title: '主页'}, 
      component: () => import('@/view/Home.vue'),
      redirect: '/index',
      children: [
        {
          path: '/index',
          meta: {
            title: '首页'
          },
          component: () => import('@/view/Welcome.vue'),
        },
        {
          path: '/user/list',
          meta: {
            title: '用户管理'
          },
          component: () => import('@/view/user/Index.vue'),
        },
        {
          path: '/user/detail',
          meta: {
            title: '用户详情'
          },
          component: () => import('@/view/user/Detail.vue'),
        },
        {
          path: '/course/list',
          meta: {
            title: '课程管理'
          },
          component: () => import('@/view/course/Index.vue'),
        },
        {
          path: '/course/add',
          meta: {
            title: '新增课程'
          },
          component: () => import('@/view/course/Add.vue'),
        },
        {
          path: '/course/update',
          meta: {
            title: '编辑课程'
          },
          component: () => import('@/view/course/Add.vue'),
        },
        {
          path: '/course/detail',
          meta: {
            title: '课程详情'
          },
          component: () => import('@/view/course/Detail.vue'),
        },
      ]
    },
  ]
})

router.beforeEach((to, from, next) => {
  //放行登录页面
  // if (to.path === '/login') {
  //   return next()
  // }
  // //获取token
  // const tokenStr = sessionStorage.getItem('token')
  // if (!tokenStr) {
  //   return next('/login')
  // } else {
  //   next()
  // }
  next()
})
export default router